package main

import (
	"fmt"
	"reflect"
)

type Animal interface {
	shout() string
}

type Dog struct {
	name string
}

func (self *Dog) shout() string {
	return fmt.Sprintf("wang wang")
}

type Cat struct {
	name string
}

func (self *Cat) shout() string {
	return fmt.Sprintf("miao miao")
}

func main() {
	var animal Animal = &Dog{}
	switch a := animal.(type) {
	case nil: // a的类型是 Animal
		fmt.Println("nil", a)
	case *Dog, *Cat: // a的类型是 Animal
		fmt.Println("typeof:", reflect.TypeOf(a)) // 输出 {}
		// fmt.Println(a.name) 这里会报错，因为 Animal 类型没有成员name
	default: // a的类型是 Animal
		fmt.Println("default", reflect.TypeOf(a), a)
	}
}
